﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_Hotel_ctrHotelDetails : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLang = Support.GetDefaultLanguage();
    private int nPageCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLangLable();
            LoadData();
        }
    }
    private int GetCountryID()
    {
        int nCountry = ConvertData.ConvertToInt(Request.QueryString["cid"]);
        if (nCountry == 0)
            nCountry = 1;

        return nCountry;
    }

    private void LoadData()
    {
        try
        {
            int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.HOTELID]);
           
            Hotel objHotel = new Hotel();
            DataTable dtbHetel = new DataTable();
            objHotel.LoadById(nItemID);

            lnkBook.NavigateUrl = "~/HotelBooking.aspx?hid=" + nItemID + "&cid=" + ConvertData.ConvertToString(this.GetCountryID()) ;

            if (objHotel.Data.Image != "")
                imgImage.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + objHotel.Data.Image.ToString();
            else imgImage.ImageUrl = Config.ROOT + "/Images/no_image.gif";

            ltrGoogleMap.Text = "<iframe width=\"630\" height=\"300\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\""
            + ConvertData.ConvertToString(objHotel.Data.GoogleMapAddress) + "\"></iframe><br /><small>View <a href=\""
            + ConvertData.ConvertToString(objHotel.Data.GoogleMapAddress)
            + "\" style=\"color: #0000FF; text-align: left\" target=\"_blank\">Hotel Address</a> in a larger map</small>";
            City objCity = new City();
            Region objRegion = new Region();
            Country objCountry = new Country();
            objCity.LoadById(objHotel.Data.CityID);
            objRegion.LoadById(objCity.Data.RegionID);
            objCountry.LoadById(objRegion.Data.CountryID);


            Support.GetStar(lblValStarRating, ConvertData.ConvertToInt(objHotel.Data.StarRating));

      
            lblCountry.Text = MultipleLanguage.LOCATION[nCurrentLang - 1];
            

            switch (nCurrentLang)
            {
                case 1:
                    lblValCity.Text = objCity.Data.CityName1;
                    lblValRegion.Text = objRegion.Data.RegionName1;
                    lblValCountry.Text = objCountry.Data.CountryName1;
                    lblTitle.Text = objHotel.Data.Title1;
                    lblValAddress.Text = objHotel.Data.Address1;
                    lblValPriceFrom.Text = "$" + ConvertData.ConvertToString(Support.FormatCurrency(objHotel.Data.PriceFrom1)).Replace(".", "");
                    lblValPriceFromTo.Text = "$" + ConvertData.ConvertToString(Support.FormatCurrency(objHotel.Data.PriceFromTo1)).Replace(".", "");
                    ltrContent.Text = objHotel.Data.Content1;
                    lblInitContent.Text = objHotel.Data.InitContent1;
                    break;
                case 2:
                    lblValCity.Text = objCity.Data.CityName2;
                    lblValRegion.Text = objRegion.Data.RegionName2;
                    lblValCountry.Text = objCountry.Data.CountryName2;
                    lblTitle.Text = objHotel.Data.Title2;
                    lblValAddress.Text = objHotel.Data.Address2;
                    lblValPriceFrom.Text = "$" + ConvertData.ConvertToString(Support.FormatCurrency(objHotel.Data.PriceFrom2)).Replace(".", "");
                    lblValPriceFromTo.Text = "$" + ConvertData.ConvertToString(Support.FormatCurrency(objHotel.Data.PriceFromTo2)).Replace(".", "");
                    ltrContent.Text = objHotel.Data.Content2;
                    lblInitContent.Text = objHotel.Data.InitContent2;
                    break;
                case 3:
                    lblValCity.Text = objCity.Data.CityName3;
                    lblValRegion.Text = objRegion.Data.RegionName3;
                    lblValCountry.Text = objCountry.Data.CountryName3;
                    lblTitle.Text = objHotel.Data.Title3;
                    lblValAddress.Text = objHotel.Data.Address3;
                    lblValPriceFrom.Text = "$" + ConvertData.ConvertToString(Support.FormatCurrency(objHotel.Data.PriceFrom3)).Replace(".", "");
                    lblValPriceFromTo.Text = "$" + ConvertData.ConvertToString(Support.FormatCurrency(objHotel.Data.PriceFromTo3)).Replace(".", "");
                    ltrContent.Text = objHotel.Data.Content3;
                    lblInitContent.Text = objHotel.Data.InitContent3;
                    break;
            }


            DataTable dtbHotel = new DataTable();
            HotelImages objImage = new HotelImages();
            dtbHotel = objImage.Search(nItemID, 1, 10000, ref nPageCount);
            rptGallery.DataSource = dtbHotel;
            rptGallery.DataBind();
        }
        catch
        {
            Response.Redirect("~/Default.aspx");
        }
    }
    private void SetLangLable()
    {
        lblOverview.Text = MultipleLanguage.LBL_FACILITIES[nCurrentLang - 1];
        lblImage.Text = MultipleLanguage.PICTURE_DETAIS[nCurrentLang - 1];
        lblLocation.Text = MultipleLanguage.LOCATION[nCurrentLang - 1];
      
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nCurrentLang - 1];
        lblPriceFrom.Text = MultipleLanguage.PRICE[nCurrentLang - 1];
      
    }
    protected void rptGallery_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nDefaulLang = Support.GetDefaultLanguage();
        int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Image imgImage = (Image)e.Item.FindControl("imgImage");
            imgImage.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "FileName"));
        }
    }
}